package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallSalesrecord;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.SalesrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class SalesrecordController {
    @Value("${server.port}")
    String port;//用来保存application.yml中的server.port的值



    @Autowired
    SalesrecordService salesrecordService;

    @RequestMapping("/salesrecord/selectById")
    public ServerResult selectById(Integer id){
        MallSalesrecord mallSalesrecord = salesrecordService.selectById(id);
        return new ServerResult(0,"成功",mallSalesrecord);


    }
    @RequestMapping("/salesrecord/insert")
    public ServerResult insert(MallSalesrecord mallSalesrecord){
        Integer insertRow = salesrecordService.insert(mallSalesrecord);
        if (insertRow>=1){
            return new ServerResult(0,"成功",null);
        }else {
            return new ServerResult(1,"失败",null);
        }


    }
    @RequestMapping("/salesrecord/selectAll")
    public ServerResult selectAll(){
        List<MallSalesrecord> mallSalesrecords = salesrecordService.selectAll();
        return new ServerResult(0,"查询成功"+port,mallSalesrecords);
    }

    @RequestMapping("/salesrecord/delectById")
    public ServerResult delectById(Integer id){
        Integer integer = salesrecordService.deleteById(id);
        if (integer>=1){
            return new ServerResult(0,"删除成功",null);

        }
        return new ServerResult(1,"删除失败",null);
    }

    @RequestMapping("/salesrecord/updateById")
    public ServerResult updateById(MallSalesrecord mallSalesrecord){
        Integer updateRow = salesrecordService.updateById(mallSalesrecord);
        if (updateRow>=1){
            return new ServerResult(0,"修改成功",null);

        }
        return new ServerResult(1,"修改失败",null);
    }

}